-- This script is part of Advanced Forge System
-- Copyright (C) 2012 XTibia, Oneshot
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

function onSay(cid, words, param, channel)
    local ret = {}
    
    local msg = "          ADVANCED FORGE SYSTEM\n"
    
    
    for _, recipe in ipairs(Recipes) do
        local skills = true
        for skillid, value in pairs(recipe.skills) do
            if getPlayerSkillLevel(cid, skillid) < value then
                skills = false
                break
            end
        end
        
        if skills == true then
            if getPlayerLevel(cid) >= recipe.level and getPlayerMagLevel(cid) >= recipe.maglevel then
                table.insert(ret, {recipe, true})
            else
                table.insert(ret, {recipe, false})
            end
        else
            table.insert(ret, {recipe, false})
        end
    end
    
    for _, recipe in ipairs(ret) do
        msg = msg .."\nRecipe for ".. getItemNameById(recipe[1].itemtype) ..":\n\n"
        if recipe[2] == true then
            for _, item in ipairs(recipe[1].items) do
                local thing = getPlayerItemById(cid, true, item[1])
                msg = msg .."* ".. getItemNameById(item[1]) .." [".. math.min(item[2], math.max(0, thing.type)) .."/".. item[2] .."]\n"
            end
        else
            msg = msg .."[LOCKED]\n"
        end
    end
    doShowTextDialog(cid, 2555, msg)
    return true
end